// 添加背景和静态的东西

function BgSprite(option) {
  this.left = option.x || 0;
  // 图片坐标的x
  this.top = option.y || 0;
  // 图片坐标的y
  this.height = option.h || 0;
  // 图片坐标的高
  this.width = option.w || 0;
  // 图片坐标的宽
  this.moveX = option.Mx || 0;
  // x偏移量
  this.moveY = option.My || 0;
  // y偏移量
  this.Cx = option.Cx || 0;
  // canvas的x
  this.Cy = option.Cy || 0;
  // canvas的y
  this.img = new Image();
  // 图片的路径
  this.img.src = option.url;
}
BgSprite.prototype = {
  draw: function() {
    ctx.save();
    ctx.drawImage(this.img, this.left, this.top, this.width, this.height, this.Cx, this.Cy, this.width, this.height);
    ctx.restore();
  }
}
var Bg = new BgSprite({
  x: 0,
  y: 0,
  url: "img/game_bg_2_hd.jpg",
  w: 1024,
  h: 768
});


var bottomBar = new BgSprite({
  x: 0,
  y: 0,
  url: "img/bottom-bar.png",
  w: 765,
  h: 72,
  Cx: 95,
  Cy: 768 - 70
});
var reduceCannon = new BgSprite({
  x: 0,
  y: 0,
  url: "img/cannon_minus.png",
  w: 44,
  h: 31,
  Cx: 440,
  Cy: 768 - 40
});
var addCannon = new BgSprite({
  x: 0,
  y: 0,
  url: "img/cannon_plus.png",
  w: 44,
  h: 31,
  Cx: 560,
  Cy: 768 - 40
});

function random(min, max) {
  return parseInt(Math.random() * (max - min) + min);
}

function appear(num) { //0-99
  if (num < 20 && num >= 0) { //20%
    return 0;
  } else if (num < 35 && num > 19) { //15%
    return 1;
  } else if (num < 47 && num > 34) { //12%
    return 2;
  } else if (num < 57 && num > 46) { //10%
    return 3;
  } else if (num < 65 && num > 56) { //8%
    return 4;
  } else if (num < 73 && num > 64) { //8%
    return 5;
  } else if (num < 80 && num > 72) { //7%
    return 6;
  } else if (num < 87 && num > 79) { //7%
    return 7;
  } else if (num < 92 && num > 86) { //5%
    return 8;
  } else if (num < 97 && num > 91) { //5%
    return 9;
  } else if (num < 99 && num > 96) { //2%
    return 10;
  } else if (num < 100 && num > 98) { //1%
    return 11;
  }
}

// 得分计算
function randomGetFish(m, n) { //m 炮弹 n 鱼
  var randomNum = Math.random(); //[0,1)
  var getNum = 0.2 + (m - n) * 0.01;
  if (getNum > randomNum) {
    return true;
  } else {
    return false;
  }
}
